package com.joolun.web.controller.promotion;

import java.util.ArrayList;
import java.util.List;

import com.joolun.system.domain.vo.EduSchedulingVo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.system.domain.EduScheduling;
import com.joolun.system.service.IEduSchedulingService;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 招生排期Controller
 * 
 * @author joolun
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/promotion/scheduling")
public class EduSchedulingController extends BaseController
{
    @Autowired
    private IEduSchedulingService eduSchedulingService;

    /**
     * 查询招生排期列表
     */
    @GetMapping("/list")
    public TableDataInfo list(EduScheduling eduScheduling)
    {
        startPage();
        List<EduSchedulingVo> list = eduSchedulingService.selectEduSchedulingList(eduScheduling);
        return getDataTable(list);
    }
    /**
     * 查询招生排期列表,下拉框渲染
     */
    @GetMapping("/option")
    public TableDataInfo listOption(EduScheduling eduScheduling)
    {
        List<EduSchedulingVo> list = eduSchedulingService.selectEduSchedulingList(eduScheduling);
        return getDataTable(list);
    }
    /**
     * 导出招生排期列表
     */
    @PreAuthorize("@ss.hasPermi('promotion:scheduling:export') || @ss.hasPermi('advanced:scheduling:export')")
    @Log(title = "招生排期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduScheduling eduScheduling)
    {
        List<EduSchedulingVo> list = eduSchedulingService.selectEduSchedulingList(eduScheduling);
        ExcelUtil<EduSchedulingVo> util = new ExcelUtil<EduSchedulingVo>(EduSchedulingVo.class);
        util.exportExcel(response, list, "招生排期数据");
    }

    /**
     * 获取招生排期详细信息
     */
    @GetMapping(value = "/{schedulingId}")
    public AjaxResult getInfo(@PathVariable("schedulingId") Long schedulingId)
    {
        return success(eduSchedulingService.selectEduSchedulingBySchedulingId(schedulingId));
    }

    /**
     * 新增招生排期
     */
    @PreAuthorize("@ss.hasPermi('promotion:scheduling:add') || @ss.hasPermi('advanced:scheduling:add')")
    @Log(title = "招生排期", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduScheduling eduScheduling)
    {
        eduScheduling.setCreateBy(getUsername());
        return toAjax(eduSchedulingService.insertEduScheduling(eduScheduling));
    }

    /**
     * 修改招生排期
     */
    @PreAuthorize("@ss.hasPermi('promotion:scheduling:edit') || @ss.hasPermi('advanced:scheduling:edit')")
    @Log(title = "招生排期", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduScheduling eduScheduling)
    {
        eduScheduling.setCreateBy(getUsername());
        return toAjax(eduSchedulingService.updateEduScheduling(eduScheduling));
    }

    /**
     * 删除招生排期
     */
    @PreAuthorize("@ss.hasPermi('promotion:scheduling:remove') || @ss.hasPermi('advanced:scheduling:remove')")
    @Log(title = "招生排期", businessType = BusinessType.DELETE)
	@DeleteMapping("/{schedulingIds}")
    public AjaxResult remove(@PathVariable Long[] schedulingIds)
    {
        return toAjax(eduSchedulingService.deleteEduSchedulingBySchedulingIds(schedulingIds));
    }
}
